package com.atguigu.mvc.handler;

import com.atguigu.mvc.entity.Employee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class EmpHandler {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RequestMapping("/save/emp")
    public String saveEmp(@Validated Employee employee, BindingResult bindingResult) {

        // 检查数据绑定过程中是否存在错误
        if (bindingResult.hasErrors()) {

            return "error";
        }

        logger.debug(employee.toString());

        return "target";
    }

}
